package net.documentshare.utils;

import java.io.File;
import java.io.FileInputStream;

import net.documentshare.documentconfig.DocumentConfigMgr;
import net.simpleframework.util.IoUtils;

public class UnFileUtils {
	/**
	 * 解压RAR文件
	 * @param targetPath
	 * @param absolutePath
	 */

	public static void unRar(String targetPath, String absolutePath) {
		try {
			final File targetFile = new File(targetPath);
			if (!targetFile.exists()) {
				targetFile.mkdirs();
			}
			// 系统安装winrar的路径
			String unrarCmd = DocumentConfigMgr.getDocuMgr().getValue("rar") + " x -r -p- -o+ \"" + absolutePath + "\" \"" + targetPath + "\"";
			Runtime rt = Runtime.getRuntime();
			rt.exec(unrarCmd);
		} catch (Exception e) {
		}
	}

	/**
	 * 解压ZIP
	 * @param targetPath
	 * @param absolutePath
	 */
	public static void unZip(final String targetPath, final String absolutePath) {
		final File targetFile = new File(targetPath);
		if (!targetFile.exists()) {
			targetFile.mkdirs();
		}
		try {
			IoUtils.unzip(new FileInputStream(absolutePath), targetPath);
		} catch (Exception e) {
		}
	}
}
